package org.lex.jdbc.url;


public class Variable extends CommonObject implements Comparable<Variable> {
	private String displayName = "";
	private String defaultValue = "";
	private boolean required = true;
	private boolean secret = false;

	public static Variable newInstance(String name, String displayName, String defaultValue, boolean required, boolean secret) {
		Variable v = new Variable();
		v.name = name;
		v.displayName = displayName;
		v.defaultValue = defaultValue;
		v.required = required;
		v.secret = secret;
		return v;
	}

	public void setDisplayName(String displayName) {
		this.displayName = displayName;
	}

	public void setDefaultValue(String defaultValue) {
		this.defaultValue = defaultValue;
	}

	public void setRequired(boolean required) {
		this.required = required;
	}

	public void setSecret(boolean secret) {
		this.secret = secret;
	}

	public String getDisplayName() {
		return displayName;
	}

	public boolean isRequired() {
		return required;
	}

	public boolean isSecret() {
		return this.secret;
	}

	public String getDefaultValue() {
		return defaultValue;
	}

	@Override
	public Variable clone() {
		try {
			return (Variable) super.clone();
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public boolean equals(Object o) {
		if (null == o) {
			return false;
		} else if (this == o) {
			return true;
		} else {
			if (true == o instanceof Variable) {
				Variable v = (Variable) o;
				return v.name.equals(name);
			}
		}
		return false;
	}

	@Override
	public int hashCode() {
		return name.hashCode();
	}

	@Override
	public int compareTo(Variable o) {
		return name.compareTo(o.name);
	}

	public String toString() {
		StringBuilder buf = new StringBuilder();
		buf.append("[var name=").append(name);
		buf.append(", displayName=").append(displayName);
		buf.append(']');
		return buf.toString();
	}
}
